<?php

//No direct access
defined('_JEXEC') or die('Restricted access');

?>

<div id="ownservices">
 <div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
		<h3>
			<?php 
				if($this->row->id) { 
					echo JText::_('OWNSERVICE_EDIT_USER'); 
				} else { 
					echo JText::_('OWNSERVICE_NEW_USER'); 
				} 
			?>
		</h3>
		<hr />
		<?php 
			$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
			$row = $this->row;
		?>
		<script language="javascript" type="text/javascript">
			<!--
				function submitbutton(pressbutton)
				{
					var form = document.adminForm;
					if (pressbutton == 'cancel') {
						submitform( pressbutton );
						return;
					}
					if (form.firstname.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_FIRSTNAME', true ); ?>" );
					} else if (form.lastname.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_LASTNAME', true ); ?>" );
					} else if (form.birthday.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_BIRTHDAY', true ); ?>" );
					} else if(form.group_id.value == "") {
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_SELECT_ACCESS_LEVEL', true ); ?>" );
					} else if(form.address.value == "") {
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_ADDRESS', true ); ?>" );
					} else if(form.city.value == "") {
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_CITY', true ); ?>" );
					} else if (form.state.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_STATE', true ); ?>" );
					} else if (form.postcode.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_POSTCODE', true ); ?>" );
					} else if (form.country.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_COUNTRY', true ); ?>" );
					} else if (form.phone_no.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_PHONE', true ); ?>" );
					} else if (form.email.value == ""){
						alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_INPUT_EMAIL', true ); ?>" );
					} else {
						if(!checkDate(form.birthday.value)) {
							alert( "<?php echo JText::_( 'OWNSERVICE_PLEASE_BIRTHDAY_FORMAT_IS_WRONG', true ); ?>" );
							return false;
						}
						submitform( pressbutton );
					}
				}
			//-->
		</script>

		<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm" enctype="multipart/form-data">

			<table class="admintable">

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_FIRSTNAME'); ?> <span class="red">*</span></td>

					<td>

						<input type="text" name="firstname" value="<?php echo $row->firstname; ?>" class="inputbox" style="width: 250px;" />

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_LASTNAME'); ?> <span class="red">*</span></td>

					<td>

						<input type="text" name="lastname" value="<?php echo $row->lastname; ?>" class="inputbox" style="width: 250px;" />

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_BIRTHDAY'); ?> <span class="red">*</span></td>

					<td>

						<?php echo JHTML::_('calendar', $row->birthday, 'birthday', 'birthday', '%Y-%m-%d',array('class'=>'inputbox')); ?>

					</td>

				</tr>

				<tr>

					<td colspan="2" align="center"><hr /></td>

				</tr>

				<?php if( $row->id ): ?>

				<tr>

					<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_USERNAME'); ?> / <?php echo JText::_('OWNSERVICE_PASSWORD'); ?></h3></td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_USERNAME'); ?> <span class="red">*</span></td>

					<td>

						<?php echo $row->username; ?>

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_PASSWORD'); ?></td>

					<td>

						<input type="password" name="password" value="" autocomplete="off" class="inputbox" size="30" />

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_REPEAT_PASSWORD'); ?></td>

					<td>

						<input type="password" name="password2" value="" autocomplete="off" class="inputbox" size="30" />

					</td>

				</tr>

				<tr>

					<td colspan="2" align="center"><hr /></td>

				</tr>

				<?php endif; ?>

				<tr>

					<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_ACCESS_LEVEL'); ?></h3></td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_ACCESS_LEVEL'); ?> <span class="red">*</span></td>

					<td>

						<?php echo $this->lists['group']; ?>

					</td>

				</tr>
				<?php if($this->access->canChangeBranch): ?>
				<tr>
					<td class="key"><?php echo JText::_('OWNSERVICE_BRANCH'); ?></td>
					<td>
						<?php echo $this->lists['branch']; ?>
					</td>
				</tr>
				<?php endif; ?>
				<tr>
					<td colspan="2" align="center"><hr /></td>
				</tr>
				<tr>
					<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_CONTACT'); ?></h3></td>
				</tr>
				<tr>
					<td class="key"><?php echo JText::_('OWNSERVICE_ADDRESS'); ?> <span class="red">*</span></td>
					<td>
						<textarea  style="width: 250px;"  class="inputbox" rows="3" name="address"><?php echo $row->address; ?></textarea>
					</td>
				</tr>
				<tr>
					<td class="key"><?php echo JText::_('OWNSERVICE_CITY'); ?> <span class="red">*</span></td>
					<td>
						<input type="text" name="city" value="<?php echo $row->city; ?>" class="inputbox" style="width: 250px;" />
					</td>
				</tr>
				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_STATE'); ?> <span class="red">*</span></td>

					<td>

						<input type="text" name="state" value="<?php echo $row->state; ?>" class="inputbox" style="width: 250px;" />

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_POSTCODE'); ?> <span class="red">*</span></td>

					<td>

						<input type="text" name="postcode" value="<?php echo $row->postcode; ?>" class="inputbox" size="20" />

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_COUNTRY'); ?> <span class="red">*</span></td>

					<td>

						<?php echo $this->lists['country']; ?>

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_PHONE'); ?> <span class="red">*</span></td>

					<td>

						<input type="text" name="phone_no" value="<?php echo $row->phone_no; ?>" class="inputbox" size="20" />

					</td>

				</tr>

				<tr>

					<td class="key"><?php echo JText::_('OWNSERVICE_EMAIL'); ?> <span class="red">*</span></td>

					<td>

						<input type="text" name="email" value="<?php echo $row->email; ?>" class="inputbox" style="width: 250px;" />

					</td>

				</tr>

				<tr>

					<td colspan="2" align="center"><hr /></td>

				</tr>
				
				<?php if(count($this->files) > 0 ): ?>
				<tr>
					<td class="key"><?php echo JText::_('OWNSERVICE_ATTACH_FILE'); ?></td>
					<td>
						<?php 
							foreach($this->files as $file):
						?>
						<div style="margin-right: 5px;">
						<?php
								if(OwnserviceHelper::isImage($file->filename)):
						?>
									<a class="img-preview" href="<?php echo JURI::root(true).'/'.OwnserviceHelper::getParams('path', 'images/stories/ownservices').'/'.$row->user_id.'/'.$file->filename ?>"><img src="<?php echo JURI::root(true).'/'.OwnserviceHelper::getParams('path', 'images/stories/ownservices').'/'.$row->user_id.'/'.$file->filename ?>" style="border: 1px solid silver;" width="<?php echo $file->width; ?>" height="<?php echo $file->height; ?>" /></a>
									<br />
									<input type="checkbox" name="delete[]" value="<?php echo $file->id; ?>"> <?php echo JText::_( 'OWNSERVICE_FILE_DELETE' ) ?>
						<?php 
								else:
									$icon = '';
									$icon	= JHTML::image(OwnserviceHelper::addIcon( $file ), $file->ext, 'class="icon-mime"') .'&nbsp;';
						?>
									<?php echo $icon ?><a href="index.php?option=com_ownservice&controller=user&task=download&id=<?php echo $file->id; ?>"><?php echo $file->filename; ?></a>
									<br />
									<input type="checkbox" name="delete[]" value="<?php echo $file->id; ?>"> <?php echo JText::_( 'OWNSERVICE_FILE_DELETE' ) ?>
						<?php
								endif;
						?>
						</div>
						<?php
							endforeach;
						?>
					</td>
				</tr>
				<tr>

					<td colspan="2" align="center"><hr /></td>

				</tr>
				<?php endif; ?>

				<tr>
					<td class="key"><?php echo JText::_('OWNSERVICE_FILES'); ?></td>
					<td>
						<ul id="addfile">
							<li>
								<input type="file" name="Filedata[]" value="" />
							</li>
						</ul>
						<input class="inputbox" type="button" name="addbutton" id="addbutton" onclick="addUploadFile();" value="<?php echo JText::_('OWNSERVICE_ADD_FILE'); ?>" style="border: 1px solid silver;" />
					</td>
				</tr>

				<tr>

					<td colspan="2" align="center"><hr /></td>

				</tr>

				<tr>

					<td colspan="2" align="center">

					<input type="button" name="save" value="<?php echo JText::_('OWNSERVICE_SAVE'); ?>" onClick="javascript: submitbutton('save')" />

					<input type="button" name="cancel" value="<?php echo JText::_('OWNSERVICE_CANCEL'); ?>" onClick="javascript: submitbutton('cancel')" />

					</td>

				</tr>

			</table>

			<input type="hidden" name="id" value="<?php echo $row->id; ?>" />

			<input type="hidden" name="user_id" value="<?php echo $row->user_id; ?>" />

			<input type="hidden" name="option" value="com_ownservice" />

			<input type="hidden" name="task" value="save" />

			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />

			<input type="hidden" name="controller" value="user" />

			<input type="hidden" name="view" value="user" />

			<?php echo JHTML::_( 'form.token' ); ?>

		</form>

	</div>

</div>